import {createSlice, createAsyncThunk} from '@reduxjs/toolkit';
import request from 'axios';
export const appSlice = createSlice({
  name: 'App',
  initialState: {
    temperature: '',
  },
  reducers: {},
  extraReducers(buildler) {
    buildler.addCase(getTemperature.fulfilled, (state, action) => {
      state.temperature = action.payload;
    });
  },
});
export const getTemperature = createAsyncThunk(
  'app/getTemperature',
  async () => {
    const {
      data: {lives},
    } = await request({
      url: 'https://restapi.amap.com/v3/weather/weatherInfo',
      params: {
        key: '62e4a5947567b50561ac03df781c518c',
        city: '330800',
        extensions: 'base',
      },
    });
    return lives[0].temperature;
  },
);
export const actions = appSlice.actions;
export default appSlice.reducer;
